﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI.WebControls;

namespace Ecreate.Web.utility
{

    public class GridViewTemplateLabel: System.Web.UI.ITemplate
    {
        private DataControlRowType templateType;
        private string columnName;
        private string dataField;


        private string _LabelText = "";

        public string LabelText
        {
            get { return _LabelText; }
            set { _LabelText = value; }
        }

        private EventHandler _handler = null;

        public EventHandler Handler
        {
            get { return _handler; }
            set { _handler = value; }
        }



        public GridViewTemplateLabel(DataControlRowType type, string colname, string datafield,EventHandler PHandler)
        {
            templateType = type;
            columnName = colname;
            dataField = datafield;
            this.Handler = PHandler;

        }
        public GridViewTemplateLabel(DataControlRowType type, string colname, string datafield)
        {
            templateType = type;
            columnName = colname;
            dataField = datafield;
        }


        public void InstantiateIn(System.Web.UI.Control container)
        {
            switch (templateType)
            {
                case DataControlRowType.Header:
                    Literal lc = new Literal();
                    lc.Text = columnName;
                    container.Controls.Add(lc);
                    break;
                case DataControlRowType.DataRow:
                    Label lb = new Label();
                    lb.ID = container.ClientID;
                    if (Handler != null)
                    {
                        lb.DataBinding += new EventHandler(Handler);
                    }
                    container.Controls.Add(lb);
                    break;
                default:
                    break;
            }
        }
    }
}
